import java.lang.reflect.InvocationTargetException;
import java.util.ResourceBundle;

/**
 * @author dhanji@gmail.com (Dhanji R. Prasanna)
 */
public class CreatingAnObjectViaReflection {

    public static void main(String[] args) {
        ResourceBundle config = ResourceBundle.getBundle("oscache.properties");

        String className = config.getString("cache.persistence.class");

        Class<?> listener;
        try {
            listener = Class.forName(className);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException("failed to find specified class", e);
        }

        Object instance;
        try {
            instance = listener.getConstructor().newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException("failed to instantiate listener from class", e);

        } catch (IllegalAccessException e) {
            throw new RuntimeException("failed to instantiate listener from class", e);

        } catch (InvocationTargetException e) {
            throw new RuntimeException("failed to instantiate listener from class", e);

        } catch (NoSuchMethodException e) {
            throw new RuntimeException("failed to instantiate listener from class", e);

        }
    }

}
